//
//  ZZMainViewController.swift
//  web
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

import UIKit

class ZZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //中间按钮
        let bnt = ZZTabBar()
        //2. 实例化闭包
        bnt.closuer = {
            // 4. 闭包回调
//            print("监听到了➕按钮的点击")
            //实例化 撰写按钮
            let composeView = ZZComposeView()
//            self.view.addSubview(composeView)
            composeView.show(target: self)
        }
        
        
        setValue(bnt, forKey: "tabBar")
        addChildViewController(ZZHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(ZZMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(ZZDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(ZZProfileViewController(), title: "我的", imgName: "tabbar_profile")
        
        
    }
    
    func addChildViewController(_ childController: UIViewController, title:String, imgName:String) {
        
        childController.title = title;
//        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIColor.orange], for: UIControlState.selected)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: UIControlState.selected)
        childController.tabBarItem.image = UIImage(named: imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        addChildViewController(ZZNavViewController(rootViewController: childController))
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
